﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO ;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Adm_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
					    
    }
    
				protected void ButtonCrypta_Click(object sender, EventArgs e)
				{
						var ut = new UtilsAdmin();
				  try{

								string fp = Request.ServerVariables["APPL_PHYSICAL_PATH"];
								var curDir = Directory.GetCurrentDirectory();
								string rapp = Request.ApplicationPath;
								string[] confFiles = Directory.GetFiles(fp, "*.config");

        string txt ="Directory.GetCurrentDirectory() = "+ curDir +"</br>\n\r"+
								"Request.ApplicationPath = " + rapp + "</br>" +
        "Request.ServerVariables['APPL_PHYSICAL_PATH'] = "+ fp +"</br>" +
        "Files .config trovati : "+ confFiles.Length.ToString() + "</br>";
        foreach (var item in confFiles)
								{
										txt+= item +"</br>";
								}   
								txt+="\n";
								if(confFiles.Length > 0 )
								{
										try { ut.criptaConnString();txt +="<b>1° tentativo crypt. ok</b> \n" ; }
										catch (Exception ex) { txt += "1° errori :\n" + ex.Message + "\n\n"; }
										try { ut.EncryptConnString(Request.ApplicationPath) ;txt += "\n<b>2° tentativo crypt. ok</b> \n"; }
										catch (Exception ex) { txt += "2° errori :\n" + ex.Message + "\n\n"; }
										try { ut.ProtectSection(confFiles[0]); txt += "\n<b>3° tentativo crypt. ok </b>\n"; }
										catch (Exception ex) { txt += "3° errori :\n" + ex.Message + "\n\n"; }
								}
								else
								 txt += "<b>Crypt non effettuato per mancanza di files .config</b>";
								
									LitMsg.Text= txt ;
						}
						catch (Exception ex)
						{	
								LitMsg.Text = ex.Message ;
						} 
				}//fM
				
}//fC
